package se137.hrbust.hlgshopping137.service.Impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import se137.hrbust.hlgshopping137.entity.OrderInfo137;
import se137.hrbust.hlgshopping137.entity.OrderItem137;
import se137.hrbust.hlgshopping137.service.OrderInfo137Service;
import se137.hrbust.hlgshopping137.mapper.OrderInfo137Mapper;
import org.springframework.stereotype.Service;
import se137.hrbust.hlgshopping137.service.OrderItem137Service;
import se137.hrbust.hlgshopping137.utils.Result137;
import se137.hrbust.hlgshopping137.vo.OrderVO137;

import java.util.List;

/**
* @author ZhaoSY
* @description 针对表【tb_order_info137(订单信息表)】的数据库操作Service实现
* @createDate 2025-09-12 14:34:13
*/
@Service
public class OrderInfo137ServiceImpl extends ServiceImpl<OrderInfo137Mapper, OrderInfo137>
    implements OrderInfo137Service{
    @Autowired
    private OrderItem137Service orderItem137Service;
    @Autowired
    private OrderInfo137Mapper orderInfo137Mapper;
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Result137 addOrder(OrderVO137 orderVO137) {//保证事务性
        OrderInfo137 orderInfo = new OrderInfo137();

        orderInfo.setOrderno(System.currentTimeMillis() +  "");
        boolean save = this.save(orderInfo);
        List<OrderItem137> orderItems = orderVO137.getOrderItems();
        for (OrderItem137 orderItem : orderItems) {
            orderItem.setOrderid(orderInfo.getId());
            orderItem137Service.save(orderItem);

        }
        return new Result137().ok("添加成功");
    }

    public Result137 deleteOrder(Long id) {
//
        orderInfo137Mapper.deleteById(id);
        return new Result137().ok("删除成功");
    }
    public Result137 updateOrderState(Long id,Integer state) {
       orderInfo137Mapper.updateOrderState(id,state);
       return new Result137().ok("修改成功");
    }
}




